// For facebook
window.fbAsyncInit = function() {
  FB.init({
    appId      : '1a38e31f71b216b68bb4a571fa8bdd2c', // App ID
    status     : true, // check login status
    cookie     : true, // enable cookies to allow the server to access the session
    oauth      : true, // enable OAuth 2.0
    xfbml      : true  // parse XFBML
  });
};

  // Load the SDK Asynchronously
  (function(d){
   var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
   js = d.createElement('script'); js.id = id; js.async = true;
   js.src = "//connect.facebook.net/en_US/all.js";
   d.getElementsByTagName('head')[0].appendChild(js);
  }(document));

  // End Facebook
	
function create_tab(name)
{
	jQuery(name + ' ul li').each(//find each list item
		function(index) {
			var a = jQuery(this).find('a');//get anchor tag
			jQuery(a.attr('href')).hide();//hide target div
			jQuery(a.attr('href')).addClass('contents');
			
			a.click(function(){//add click event
				jQuery(name + ' ul li').each(//for each list item
					function(index){
						var li_a = jQuery(this).find('a');//hide their target and unset active
						jQuery(li_a.attr('href')).hide();
						li_a.removeClass('active');
					}
				);
				
				jQuery(a.attr('href')).show();//show clicked item
				jQuery(this).addClass('active');//add active class
			});
	});
	
	var first = jQuery(name + ' ul li').first();
	var first_a = first.find('a')
	jQuery(first_a.attr('href')).show();
	first_a.addClass('active');
}

function create_header(name, width)
{
	jQuery(name).wrap('<div class="header"></div>');
	jQuery(name).before(
		'<div class="div1" style="width:' + width + ';">' +
			'<div class="div2">' +
				'<div class="div3"></div>' +
			'</div>' +
		'</div>');
	jQuery(name).wrap('<div class="content" style="text-align:center;width:' + width + '"></div>');
}	

function create_scrollable(name, max_items, current_item, label)
{
	jQuery(name + ' li').each(
		function(index) {			
			jQuery(this).hide();	
			jQuery(this).addClass('scrollable');
		}
	);
	
	var ci = jQuery(current_item);
	var i = 0;
	
	ci.addClass('active');
	
	for(i = 0; i < max_items; i++)
	{
		ci.show();
		ci = ci.next();
		if(ci.html() == null)
		{
			break;
		}
	}
	
	var ci = jQuery(current_item);
	
	for(i = max_items - i; i > 1; i--)
	{
		ci = ci.prev();
		ci.show();
	}
	
	
	jQuery(name).prepend('<li><a href="javascript:scroll_left(\'' + name + '\')">&lt;&lt;</a></li>');
	if(label)
		jQuery(name).prepend('<li style="width:50px; font-weight:bold; font-size:1.2em;">' + label + '</li>');
	jQuery(name).append('<li><a href="javascript:scroll_right(\'' + name + '\')">&gt;&gt;</a></li>');	
}

function scroll_left(name)
{	
	var first = jQuery(name + ' .scrollable:visible').first();
	
	if(first.prev().html() != null && first.prev().hasClass('scrollable'))
	{
		first.prev().show();
		jQuery(name + ' .scrollable:visible').last().hide();
	}
}

function scroll_right(name)
{	
	var last = jQuery(name + ' .scrollable:visible').last();
	
	if(last.next().html() != null && last.next().hasClass('scrollable'))
	{
		last.next().show();
		jQuery(name + ' .scrollable:visible').first().hide();
	}
}

function show_table_partial(container){

	var anchor = jQuery(container + ' a');
	anchor.bind('click', function(){
		var trs    = jQuery(container + ' table tbody tr');
		var count  = 0;
		trs.each(
			function(index){
				var display = this.style.display;
				if(display == "none")
				  jQuery(this).fadeIn();
				else{
				  if(count++ > 6)
					jQuery(this).fadeOut();
			    }
			}
		);
		return false;
	});
	
}
	